/*
 * @Author: Eureka 
 * @Date: 2019-12-04 16:29:23 
 * @Last Modified by: Eureka
 * @Last Modified time: 2021-06-07 10:17:43
 */

import 'dart:convert';

/// fluro 参数编码解码工具类
class FluroConvertUtils {
  /// fluro 传递中文参数前，先转换，fluro 不支持中文传递
  static String fluroCnParamsEncode(String originalCn) {
    try {
      StringBuffer sb = StringBuffer();
      var encoded = const Utf8Encoder().convert(originalCn);
      for (var val in encoded) {
        sb.write('$val,');
      }
      return sb.toString().substring(0, sb.length - 1).toString();
    } catch (e) {
      return "";
    }
  }

  /// fluro 传递后取出参数，解析
  static String fluroCnParamsDecode(String encodedCn) {
    try {
      var decoded = encodedCn.split('[').last.split(']').first.split(',');
      var list = <int>[];
      for (var s in decoded) {
        list.add(int.parse(s.trim()));
      }
      return const Utf8Decoder().convert(list);
    } catch (e) {
      return "";
    }
  }
}
